package secondBrush.array;

import java.util.Arrays;
import java.util.List;

public class E02Leetcode27 {
    public int removeElement(int[] nums, int val) {
        int length = nums.length;
        int k = length;
        for (int i = 0; i < length; i++) {
            if (nums[i] == val) {
                nums[i] = -1;
                k -= 1;
            }
        }
        Arrays.sort(nums); ;
        for (int i = 0; i < length / 2; i++) {
            int temp = nums[i];
            nums[i] = nums[length - 1 - i];
            nums[length - 1 - i] = temp;
        }
        return k;

    }
    public static int removeElement2(int[] nums, int val) {
        int ans = 0;
        for(int num: nums) {
            if(num != val) {
                nums[ans] = num;
                ans++;
            }
        }
        return ans;
    }

    public static int removeElement3(int[] nums, int val) {
        int ans = 0;
        for(int num: nums) {
            if(num != val) {
                nums[ans] = num;
                ans++;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] nums = {3, 2, 2, 3};
        int val = 2;
        removeElement2(nums, val);


    }

}
